import { useEffect } from "react";
import { Navigate, useLocation } from "react-router";

const BeforeEach = (props: any) => {

    let token=sessionStorage.getItem("token");
    // let permission = ["/demo"];
    const location = useLocation();
    if(location.pathname == "/login"){
        return (
            <>
                {props.children}
            </>
        )
    }
    if (!token) {
        return (
            <Navigate to="/login" />
        )
    }
    return (
        <>
            {props.children}
        </>

    )

}
export default BeforeEach;